<template>
  <ul class="list">
    <li
      class="item"
      @click="handleLetterClick"
      v-for="(item,key) in qList"
      :key="key"
      @touchstart="handleTouchStart"
      @touchmove="handleTouchMove"
      @touchend="handleTouchEnd"
      :ref='item'
    >{{item}}</li>
  </ul>
</template>

<script>
export default {
  data() {
    return {
      qList: [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "J",
        "K",
        "L",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "W",
        "X",
        "Y",
        "Z"
      ]
    };
  },
  methods: {
    handleLetterClick(e) {
      console.log(e.target.innerText);
      this.$emit("change", e.target.innerText); //发送
    },
    handleTouchStart() {
      this.touchStatus = true;
    },
    handleTouchMove(e) {
      if (this.touchStatus) {
        //A字符距离顶部的距离
        const startY = this.$refs["A"][0].offsetTop;
        console.log(startY);
        //所触控区距离最顶部距离e.touches[0].clientY   79为量出来量出来header高43+search高为36
        const touchY = e.touches[0].clientY - 79;
        console.log(touchY);
        // index触控位置的下标   20量为字符的高度
        const index = Math.floor((touchY - startY) / 20);
        console.log(index);
        if (index >= 0 && index < this.qList.length) {
          this.$emit("change", this.qList[index]);
        }
      }
    },
    handleTouchEnd() {
      this.touchStatus = false;
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl';

.list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: absolute;
  top: 1.58rem;
  right: 0;
  bottom: 0;
  width: 0.44rem;

  // background :red
  .item {
    line-height: 0.4rem;
    text-align: center;
    color: $bgColor;
  }
}
</style>
